package com.triones.ljr.controller.web;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.triones.ljr.entity.dto.BannerDO;
import com.triones.ljr.entity.vo.BannerVO;
import com.triones.ljr.service.BannerService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 广告图
 *
 * @Author: triones
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/banner")
public class BannerController extends BaseController {

    private final BannerService bannerService;

    /**
     * 列表（分页）
     */
    @SaCheckPermission("system:banner:pageList")
    @GetMapping("/pageList")
    public TableDataInfo<BannerVO> pageList(String keyword, PageQuery pageQuery) {
        return bannerService.pageList(keyword, pageQuery);
    }

    /**
     * 新增
     */
    @SaCheckPermission("system:banner:add")
    @Log(title = "广告图管理", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody BannerDO dto) {
        return toAjax(bannerService.add(dto));
    }

    /**
     * 修改
     */
    @SaCheckPermission("system:banner:edit")
    @Log(title = "广告图管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@Validated @RequestBody BannerDO dto) {
        return toAjax(bannerService.edit(dto));
    }

    /**
     * 获取详情
     */
    @GetMapping("/{id}")
    public R<BannerVO> getInfo(@PathVariable Long id) {
        return R.ok(bannerService.getInfo(id));
    }

    /**
     * 删除
     */
    @SaCheckPermission("system:banner:remove")
    @Log(title = "广告图管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public R<Void> remove(@PathVariable Long id) {
        return toAjax(bannerService.remove(id));
    }

    /**
     * 状态修改
     */
    @Log(title = "广告图管理-上下架", businessType = BusinessType.UPDATE)
    @PutMapping("/changeShowStatus")
    public R<Void> changeShowStatus(@RequestBody BannerDO dto) {
        return toAjax(bannerService.updateShowStatus(dto));
    }
}
